package firstStage.part6;

/**
 * @ClassName: [Demo2]
 * @Description: 数组反转
 * @Author: [黄劲松]
 * @CreateDate: [2021-02-06]
 * @Version: [v1.0]
 */
public class Demo2 {
    public static void main(String[] args) {
        int[] array = {12, 23, 43, 54, 65, 76, 87, 97};
        reverse(array);
        //遍历数组
        printArray(array);
    }

    public static void reverse(int[] array) {
        for (int start = 0, end = array.length - 1; start <= end; start++, end--) {
            int temp = array[start];
            array[start] = array[end];
            array[end] = temp;
        }
    }

    public static void printArray(int[] array) {
        System.out.print("{");
        for (int i = 0; i < array.length; i++) {
            if (i == array.length - 1) {
                System.out.print(array[i]);
            } else {
                System.out.print(array[i] + ", ");
            }
        }
        System.out.println("}");
    }
}
